#ifndef AUTOGENCODEGENERATOR_H
#define AUTOGENCODEGENERATOR_H

#include <DefineLibReflection.h>
#include <DefineCommon.h>
#include <CppInfo.h>

//This is the new version of reflection code generation
class AutogenCodeGenerator;
typedef SmartPtr(AutogenCodeGenerator) AutogenCodeGeneratorPtr;
class REFLECTION_DLL AutogenCodeGenerator 
{
public:
    AutogenCodeGenerator();
    ~AutogenCodeGenerator();

    /**The output data of wrap code generation*/
    EList<CppInfo::ClassPtr> m_wrapClassList;

    /**write to file, this is the entry function of this class*/
    void collectionToFiles(CppInfo::CppCollectionPtr collPtr, const EString& dirName);

    /**write a Class to a h file*/
    
    virtual CppInfo::ClassPtr classToWrapClass(CppInfo::ClassPtr oldC  );

    void copyParentClassToClass(CppInfo::ClassPtr parent, CppInfo::ClassPtr c);

protected:
    void classToFile_cpp(CppInfo::ClassPtr c, const EString& fileName);

    void addWrapClassPrintInfoStr(CppInfo::ClassPtr c, EString& content);
    void replaceTemplateInclude(const EString& templateStr, CppInfo::ClassPtr c, EString& content);
    void replaceTemplateMemberFun(const EString& templateStr, CppInfo::ClassPtr c, CppInfo::FunctionPtr fun, EString& content);
    void replaceTemplateMemberVar(const EString& templateStr, CppInfo::ClassPtr c, CppInfo::VariablePtr var, EString& content);
    void replaceTemplateCreateMetaFunction(const EString& templateStr, CppInfo::ClassPtr c, EString& content);
    void replaceTemplateConstructFunction(const EString& templateStr, CppInfo::ClassPtr c, EString& content);
    void replaceTemplateFactoryFunction(const EString& templateStr, CppInfo::ClassPtr c, EString& content);
    void replaceTemplateRegistPluginFunction(const EString& templateStr, CppInfo::ClassPtr c, EString& content);
    void replaceTemplateEnd(const EString& templateStr, CppInfo::ClassPtr c, EString& content);

    /*Fill m_templateStr for code generation, be called in construct function*/
    void fillTemplateStr_cpp();
    EString m_templateInclude;
    EString m_templateMemberFunction;
    EString m_templateMemberValueSetFun;
    EString m_templateMemberValueSetFun_default;
    EString m_templateMemberValueGetFun;
    EString m_templateMemberValueGetFun_default;
    EString m_templateCreateMetaFunction;
    EString m_templateConstructFunction;
    EString m_templateFactoryFunction;
    EString m_templateRegistPluginFunction;
    EString m_templateEnd;

    void classToFile_h(CppInfo::ClassPtr c, const EString& fileName);
    void fillTemplateStr_h();
    EString m_templateInclude_h;
    EString m_templateConstructFunction_h;
    EString m_templateRegistPluginFunction_h;
    EString m_templateEnd_h;

};

#endif // AUTOGENCODEGENERATOR_H
